home *** CD-ROM | disk | FTP | other *** search
/ Cre@te Online 2000 December / Cre@teOnline CD05.iso / MacSoft / XML ConsoleMax.sea / XML ConsoleMax / Required / swingall.jar / javax / swing / tree / VariableHeightLayoutCache$TreeStateNode.class (.txt) < prev    next >
Encoding:
Java Class File  |  1999-07-15  |  8.9 KB  |  483 lines

  1. package javax.swing.tree;
  2.  
  3. import java.awt.Rectangle;
  4. import java.util.Enumeration;
  5. import java.util.Vector;
  6.  
  7. class VariableHeightLayoutCache$TreeStateNode extends DefaultMutableTreeNode {
  8.    // $FF: synthetic field
  9.    private final VariableHeightLayoutCache this$0;
  10.    protected int preferredWidth;
  11.    protected int preferredHeight;
  12.    protected int xOrigin;
  13.    protected int yOrigin;
  14.    protected boolean expanded;
  15.    protected boolean hasBeenExpanded;
  16.    protected TreePath path;
  17.  
  18.    public VariableHeightLayoutCache$TreeStateNode(VariableHeightLayoutCache var1, Object var2) {
  19.       super(var2);
  20.       this.this$0 = var1;
  21.    }
  22.  
  23.    public Enumeration children() {
  24.       return !this.isExpanded() ? DefaultMutableTreeNode.EMPTY_ENUMERATION : super.children();
  25.    }
  26.  
  27.    public void collapse() {
  28.       this.collapse(true);
  29.    }
  30.  
  31.    protected void collapse(boolean var1) {
  32.       if (this.isExpanded()) {
  33.          Vector var2 = null;
  34.          Enumeration var3 = ((DefaultMutableTreeNode)this).preorderEnumeration();
  35.          var3.nextElement();
  36.          int var4 = 0;
  37.          boolean var5 = this.this$0.isFixedRowHeight();
  38.          int var6;
  39.          if (var5) {
  40.             var6 = 0;
  41.          } else {
  42.             var6 = this.getPreferredHeight() + this.getYOrigin();
  43.          }
  44.  
  45.          int var7 = this.getPreferredHeight();
  46.          int var8 = var6;
  47.          int var9 = this.getRow();
  48.          this.expanded = false;
  49.          if (var9 == -1) {
  50.             this.markSizeInvalid();
  51.          } else if (var1) {
  52.             this.updatePreferredSize(var9);
  53.          }
  54.  
  55.          if (!var5) {
  56.             while(var3.hasMoreElements()) {
  57.                VariableHeightLayoutCache$TreeStateNode var14 = (VariableHeightLayoutCache$TreeStateNode)var3.nextElement();
  58.                if (VariableHeightLayoutCache.access$1(this.this$0).contains(var14)) {
  59.                   ++var4;
  60.                   if (this.this$0.treeSelectionModel != null && this.this$0.treeSelectionModel.isRowSelected(var4 + var9)) {
  61.                      if (var2 == null) {
  62.                         var2 = new Vector();
  63.                      }
  64.  
  65.                      var2.addElement(var14.getTreePath());
  66.                   }
  67.  
  68.                   VariableHeightLayoutCache.access$1(this.this$0).removeElement(var14);
  69.                   var6 = var14.getYOrigin() + var14.getPreferredHeight();
  70.                }
  71.             }
  72.          } else {
  73.             while(var3.hasMoreElements()) {
  74.                VariableHeightLayoutCache$TreeStateNode var10 = (VariableHeightLayoutCache$TreeStateNode)var3.nextElement();
  75.                if (VariableHeightLayoutCache.access$1(this.this$0).contains(var10)) {
  76.                   ++var4;
  77.                   if (this.this$0.treeSelectionModel != null && this.this$0.treeSelectionModel.isRowSelected(var4 + var9)) {
  78.                      if (var2 == null) {
  79.                         var2 = new Vector();
  80.                      }
  81.  
  82.                      var2.addElement(var10.getTreePath());
  83.                   }
  84.  
  85.                   VariableHeightLayoutCache.access$1(this.this$0).removeElement(var10);
  86.                }
  87.             }
  88.          }
  89.  
  90.          if (var9 != -1 && var1 && (var4 > 0 || var7 != this.getPreferredHeight())) {
  91.             var8 += this.getPreferredHeight() - var7;
  92.             if (!var5 && var9 + 1 < this.this$0.getRowCount() && var8 != var6) {
  93.                int var12 = var8 - var6;
  94.                int var15 = var9 + 1;
  95.  
  96.                for(int var11 = VariableHeightLayoutCache.access$1(this.this$0).size(); var15 < var11; ++var15) {
  97.                   ((VariableHeightLayoutCache$TreeStateNode)VariableHeightLayoutCache.access$1(this.this$0).elementAt(var15)).shiftYOriginBy(var12);
  98.                }
  99.             }
  100.  
  101.             this.didAdjustTree();
  102.             VariableHeightLayoutCache.access$8(this.this$0);
  103.          }
  104.  
  105.          if (this.this$0.treeSelectionModel != null && var4 > 0 && var9 != -1) {
  106.             if (var2 != null) {
  107.                int var16 = var2.size();
  108.                TreePath[] var17 = new TreePath[var16];
  109.                var2.copyInto(var17);
  110.                this.this$0.treeSelectionModel.removeSelectionPaths(var17);
  111.                this.this$0.treeSelectionModel.addSelectionPath(this.getTreePath());
  112.             } else {
  113.                this.this$0.treeSelectionModel.resetRowSelection();
  114.             }
  115.          }
  116.       }
  117.  
  118.    }
  119.  
  120.    protected void deepMarkSizeInvalid() {
  121.       this.markSizeInvalid();
  122.  
  123.       for(int var1 = ((DefaultMutableTreeNode)this).getChildCount() - 1; var1 >= 0; --var1) {
  124.          ((VariableHeightLayoutCache$TreeStateNode)((DefaultMutableTreeNode)this).getChildAt(var1)).deepMarkSizeInvalid();
  125.       }
  126.  
  127.    }
  128.  
  129.    protected void didAdjustTree() {
  130.    }
  131.  
  132.    public void expand() {
  133.       this.expand(true);
  134.    }
  135.  
  136.    protected void expand(boolean var1) {
  137.       if (!this.isExpanded() && !this.isLeaf()) {
  138.          boolean var2 = this.this$0.isFixedRowHeight();
  139.          int var3 = this.getPreferredHeight();
  140.          int var4 = this.getRow();
  141.          this.expanded = true;
  142.          this.updatePreferredSize(var4);
  143.          if (!this.hasBeenExpanded) {
  144.             Object var6 = this.getValue();
  145.             TreeModel var7 = this.this$0.getModel();
  146.             int var8 = var7.getChildCount(var6);
  147.             this.hasBeenExpanded = true;
  148.             if (var4 == -1) {
  149.                for(int var18 = 0; var18 < var8; ++var18) {
  150.                   VariableHeightLayoutCache$TreeStateNode var11 = VariableHeightLayoutCache.access$7(this.this$0, var7.getChild(var6, var18));
  151.                   ((DefaultMutableTreeNode)this).add(var11);
  152.                   var11.updatePreferredSize(-1);
  153.                }
  154.             } else {
  155.                int var9 = var4 + 1;
  156.  
  157.                for(int var10 = 0; var10 < var8; ++var10) {
  158.                   VariableHeightLayoutCache$TreeStateNode var5 = VariableHeightLayoutCache.access$7(this.this$0, var7.getChild(var6, var10));
  159.                   ((DefaultMutableTreeNode)this).add(var5);
  160.                   var5.updatePreferredSize(var9);
  161.                }
  162.             }
  163.          }
  164.  
  165.          int var12 = var4;
  166.          Enumeration var14 = ((DefaultMutableTreeNode)this).preorderEnumeration();
  167.          var14.nextElement();
  168.          int var15;
  169.          if (var2) {
  170.             var15 = 0;
  171.          } else if (this == VariableHeightLayoutCache.access$2(this.this$0) && !this.this$0.isRootVisible()) {
  172.             var15 = 0;
  173.          } else {
  174.             var15 = this.getYOrigin() + this.getPreferredHeight();
  175.          }
  176.  
  177.          if (!var2) {
  178.             while(var14.hasMoreElements()) {
  179.                VariableHeightLayoutCache$TreeStateNode var17 = (VariableHeightLayoutCache$TreeStateNode)var14.nextElement();
  180.                if (!VariableHeightLayoutCache.access$5(this.this$0) && !var17.hasValidSize()) {
  181.                   var17.updatePreferredSize(var12 + 1);
  182.                }
  183.  
  184.                var17.setYOrigin(var15);
  185.                var15 += var17.getPreferredHeight();
  186.                Vector var21 = VariableHeightLayoutCache.access$1(this.this$0);
  187.                ++var12;
  188.                var21.insertElementAt(var17, var12);
  189.             }
  190.          } else {
  191.             while(var14.hasMoreElements()) {
  192.                VariableHeightLayoutCache$TreeStateNode var16 = (VariableHeightLayoutCache$TreeStateNode)var14.nextElement();
  193.                Vector var10000 = VariableHeightLayoutCache.access$1(this.this$0);
  194.                ++var12;
  195.                var10000.insertElementAt(var16, var12);
  196.             }
  197.          }
  198.  
  199.          if (var1 && (var4 != var12 || this.getPreferredHeight() != var3)) {
  200.             if (!var2) {
  201.                ++var12;
  202.                if (var12 < this.this$0.getRowCount()) {
  203.                   int var20 = var15 - (this.getYOrigin() + this.getPreferredHeight()) + (this.getPreferredHeight() - var3);
  204.  
  205.                   for(int var19 = VariableHeightLayoutCache.access$1(this.this$0).size() - 1; var19 >= var12; --var19) {
  206.                      ((VariableHeightLayoutCache$TreeStateNode)VariableHeightLayoutCache.access$1(this.this$0).elementAt(var19)).shiftYOriginBy(var20);
  207.                   }
  208.                }
  209.             }
  210.  
  211.             this.didAdjustTree();
  212.             VariableHeightLayoutCache.access$8(this.this$0);
  213.          }
  214.  
  215.          if (this.this$0.treeSelectionModel != null) {
  216.             this.this$0.treeSelectionModel.resetRowSelection();
  217.          }
  218.       }
  219.  
  220.    }
  221.  
  222.    protected void expandParentAndReceiver() {
  223.       VariableHeightLayoutCache$TreeStateNode var1 = (VariableHeightLayoutCache$TreeStateNode)((DefaultMutableTreeNode)this).getParent();
  224.       if (var1 != null) {
  225.          var1.expandParentAndReceiver();
  226.       }
  227.  
  228.       this.expand();
  229.    }
  230.  
  231.    public VariableHeightLayoutCache$TreeStateNode getLastVisibleNode() {
  232.       VariableHeightLayoutCache$TreeStateNode var1;
  233.       for(var1 = this; var1.isExpanded() && ((DefaultMutableTreeNode)var1).getChildCount() > 0; var1 = (VariableHeightLayoutCache$TreeStateNode)((DefaultMutableTreeNode)var1).getLastChild()) {
  234.       }
  235.  
  236.       return var1;
  237.    }
  238.  
  239.    protected Enumeration getLoadedChildren(boolean var1) {
  240.       if (var1 && !this.hasBeenExpanded) {
  241.          Object var3 = this.getValue();
  242.          TreeModel var4 = this.this$0.getModel();
  243.          int var5 = var4.getChildCount(var3);
  244.          this.hasBeenExpanded = true;
  245.          int var6 = this.getRow();
  246.          if (var6 == -1) {
  247.             for(int var7 = 0; var7 < var5; ++var7) {
  248.                VariableHeightLayoutCache$TreeStateNode var2 = VariableHeightLayoutCache.access$7(this.this$0, var4.getChild(var3, var7));
  249.                ((DefaultMutableTreeNode)this).add(var2);
  250.                var2.updatePreferredSize(-1);
  251.             }
  252.          } else {
  253.             ++var6;
  254.  
  255.             for(int var10 = 0; var10 < var5; ++var10) {
  256.                VariableHeightLayoutCache$TreeStateNode var8 = VariableHeightLayoutCache.access$7(this.this$0, var4.getChild(var3, var10));
  257.                ((DefaultMutableTreeNode)this).add(var8);
  258.                var8.updatePreferredSize(var6++);
  259.             }
  260.          }
  261.  
  262.          return super.children();
  263.       } else {
  264.          return super.children();
  265.       }
  266.    }
  267.  
  268.    public int getModelChildCount() {
  269.       return this.hasBeenExpanded ? super.getChildCount() : this.this$0.getModel().getChildCount(this.getValue());
  270.    }
  271.  
  272.    public Rectangle getNodeBounds(Rectangle var1) {
  273.       if (var1 == null) {
  274.          var1 = new Rectangle(this.getXOrigin(), this.getYOrigin(), this.getPreferredWidth(), this.getPreferredHeight());
  275.       } else {
  276.          var1.x = this.getXOrigin();
  277.          var1.y = this.getYOrigin();
  278.          var1.width = this.getPreferredWidth();
  279.          var1.height = this.getPreferredHeight();
  280.       }
  281.  
  282.       return var1;
  283.    }
  284.  
  285.    public int getPreferredHeight() {
  286.       if (this.this$0.isFixedRowHeight()) {
  287.          return this.this$0.getRowHeight();
  288.       } else {
  289.          if (!this.hasValidSize()) {
  290.             this.updatePreferredSize(this.getRow());
  291.          }
  292.  
  293.          return this.preferredHeight;
  294.       }
  295.    }
  296.  
  297.    public int getPreferredWidth() {
  298.       if (!this.hasValidSize()) {
  299.          this.updatePreferredSize(this.getRow());
  300.       }
  301.  
  302.       return this.preferredWidth;
  303.    }
  304.  
  305.    public int getRow() {
  306.       return VariableHeightLayoutCache.access$1(this.this$0).indexOf(this);
  307.    }
  308.  
  309.    public TreePath getTreePath() {
  310.       return this.path;
  311.    }
  312.  
  313.    public Object getValue() {
  314.       return ((DefaultMutableTreeNode)this).getUserObject();
  315.    }
  316.  
  317.    public int getVisibleChildCount() {
  318.       int var1 = 0;
  319.       if (this.isExpanded()) {
  320.          int var2 = ((DefaultMutableTreeNode)this).getChildCount();
  321.          var1 += var2;
  322.  
  323.          for(int var3 = 0; var3 < var2; ++var3) {
  324.             var1 += ((VariableHeightLayoutCache$TreeStateNode)((DefaultMutableTreeNode)this).getChildAt(var3)).getVisibleChildCount();
  325.          }
  326.       }
  327.  
  328.       return var1;
  329.    }
  330.  
  331.    public int getXOrigin() {
  332.       if (!this.hasValidSize()) {
  333.          this.updatePreferredSize(this.getRow());
  334.       }
  335.  
  336.       return this.xOrigin;
  337.    }
  338.  
  339.    public int getYOrigin() {
  340.       if (this.this$0.isFixedRowHeight()) {
  341.          int var1 = this.getRow();
  342.          return var1 == -1 ? -1 : this.this$0.getRowHeight() * var1;
  343.       } else {
  344.          return this.yOrigin;
  345.       }
  346.    }
  347.  
  348.    public boolean hasBeenExpanded() {
  349.       return this.hasBeenExpanded;
  350.    }
  351.  
  352.    public boolean hasValidSize() {
  353.       return this.preferredHeight != 0;
  354.    }
  355.  
  356.    public boolean isExpanded() {
  357.       return this.expanded;
  358.    }
  359.  
  360.    public boolean isLeaf() {
  361.       return this.this$0.getModel().isLeaf(this.getValue());
  362.    }
  363.  
  364.    public boolean isVisible() {
  365.       if (this == VariableHeightLayoutCache.access$2(this.this$0)) {
  366.          return true;
  367.       } else {
  368.          VariableHeightLayoutCache$TreeStateNode var1 = (VariableHeightLayoutCache$TreeStateNode)((DefaultMutableTreeNode)this).getParent();
  369.          return var1 != null && var1.isExpanded() && var1.isVisible();
  370.       }
  371.    }
  372.  
  373.    public void makeVisible() {
  374.       VariableHeightLayoutCache$TreeStateNode var1 = (VariableHeightLayoutCache$TreeStateNode)((DefaultMutableTreeNode)this).getParent();
  375.       if (var1 != null) {
  376.          var1.expandParentAndReceiver();
  377.       }
  378.  
  379.    }
  380.  
  381.    protected void markSizeInvalid() {
  382.       this.preferredHeight = 0;
  383.    }
  384.  
  385.    public void remove(int var1) {
  386.       VariableHeightLayoutCache$TreeStateNode var2 = (VariableHeightLayoutCache$TreeStateNode)((DefaultMutableTreeNode)this).getChildAt(var1);
  387.       var2.removeFromMapping();
  388.       super.remove(var1);
  389.    }
  390.  
  391.    protected void removeFromMapping() {
  392.       if (this.path != null) {
  393.          VariableHeightLayoutCache.access$3(this.this$0, this);
  394.  
  395.          for(int var1 = ((DefaultMutableTreeNode)this).getChildCount() - 1; var1 >= 0; --var1) {
  396.             ((VariableHeightLayoutCache$TreeStateNode)((DefaultMutableTreeNode)this).getChildAt(var1)).removeFromMapping();
  397.          }
  398.       }
  399.  
  400.    }
  401.  
  402.    protected void resetChildrenPaths(TreePath var1) {
  403.       VariableHeightLayoutCache.access$3(this.this$0, this);
  404.       if (var1 == null) {
  405.          this.path = new TreePath(((DefaultMutableTreeNode)this).getUserObject());
  406.       } else {
  407.          this.path = var1.pathByAddingChild(((DefaultMutableTreeNode)this).getUserObject());
  408.       }
  409.  
  410.       VariableHeightLayoutCache.access$0(this.this$0, this);
  411.  
  412.       for(int var2 = ((DefaultMutableTreeNode)this).getChildCount() - 1; var2 >= 0; --var2) {
  413.          ((VariableHeightLayoutCache$TreeStateNode)((DefaultMutableTreeNode)this).getChildAt(var2)).resetChildrenPaths(this.path);
  414.       }
  415.  
  416.    }
  417.  
  418.    public void setParent(MutableTreeNode var1) {
  419.       super.setParent(var1);
  420.       if (var1 != null) {
  421.          this.path = ((VariableHeightLayoutCache$TreeStateNode)var1).getTreePath().pathByAddingChild(((DefaultMutableTreeNode)this).getUserObject());
  422.          VariableHeightLayoutCache.access$0(this.this$0, this);
  423.       }
  424.  
  425.    }
  426.  
  427.    public void setUserObject(Object var1) {
  428.       super.setUserObject(var1);
  429.       if (this.path != null) {
  430.          VariableHeightLayoutCache$TreeStateNode var2 = (VariableHeightLayoutCache$TreeStateNode)((DefaultMutableTreeNode)this).getParent();
  431.          if (var2 != null) {
  432.             this.resetChildrenPaths(var2.getTreePath());
  433.          } else {
  434.             this.resetChildrenPaths((TreePath)null);
  435.          }
  436.       }
  437.  
  438.    }
  439.  
  440.    protected void setYOrigin(int var1) {
  441.       this.yOrigin = var1;
  442.    }
  443.  
  444.    protected void shiftYOriginBy(int var1) {
  445.       this.yOrigin += var1;
  446.    }
  447.  
  448.    public void toggleExpanded() {
  449.       if (this.isExpanded()) {
  450.          this.collapse();
  451.       } else {
  452.          this.expand();
  453.       }
  454.  
  455.    }
  456.  
  457.    protected void updatePreferredSize() {
  458.       this.updatePreferredSize(this.getRow());
  459.    }
  460.  
  461.    protected void updatePreferredSize(int var1) {
  462.       Rectangle var2 = this.this$0.getNodeDimensions(((DefaultMutableTreeNode)this).getUserObject(), var1, ((DefaultMutableTreeNode)this).getLevel(), this.isExpanded(), VariableHeightLayoutCache.access$4(this.this$0));
  463.       if (var2 == null) {
  464.          this.xOrigin = 0;
  465.          this.preferredWidth = this.preferredHeight = 0;
  466.          VariableHeightLayoutCache.access$6(this.this$0, true);
  467.       } else if (var2.height == 0) {
  468.          this.xOrigin = 0;
  469.          this.preferredWidth = this.preferredHeight = 0;
  470.          VariableHeightLayoutCache.access$6(this.this$0, true);
  471.       } else {
  472.          this.xOrigin = var2.x;
  473.          this.preferredWidth = var2.width;
  474.          if (this.this$0.isFixedRowHeight()) {
  475.             this.preferredHeight = this.this$0.getRowHeight();
  476.          } else {
  477.             this.preferredHeight = var2.height;
  478.          }
  479.       }
  480.  
  481.    }
  482. }
  483.